//递归
def move(a,b):
    b.append(a.pop(-1))
    return b
def Hanoi(n,a,b,c):
    if n>0:
        Hanoi(n-1, a, c, b)
        b=move(a,b)
        Hanoi(n-1, c, b, a)
def Hanoire(n,a,b,c): 
    a=list(range(1,n+1))
    Hanoi(n,a,b,c) 
a=list()
b=list()
c=list()
Hanoire(10, a, b, c)
//非递归
def minre(a):
    if len(a)==0:
        return 1000
    else:
        return min(a)
def Hanoi(n,a,b,c):
    a=list(range(n,0,-1))
    lena=len(a)
    i=1
    while len(b)!=lena:
        
        if(i%2!=0):
            if minre(a)==1:
                a.remove(1)
                b.append(1)
                if(len(b)==lena):
                    break
            elif minre(b)==1:
                b.remove(1)
                c.append(1)
            elif min(c)==1:
                c.remove(1)
                a.append(1)
        else:
            if minre(a)==1:
                if minre(b)<minre(c):
                    c.append(b.pop(-1))
                else:
                    b.append(c.pop(-1))
            elif minre(b)==1:
                if minre(a)<minre(c):
                    c.append(a.pop(-1))
                else:
                    a.append(c.pop(-1))
            elif min(c)==1:
                if minre(b)<minre(a):
                    a.append(b.pop(-1))
                else:
                    try:
                        b.append(a.pop(-1))
                    except:
                        print("finish")
        i=i+1        
a=list()
b=list()
c=list()
Hanoi(10, a, b, c)  
